package com.study.system.controller;

import com.study.system.dto.ResultData;
import com.study.system.entity.Finance;
import com.study.system.service.FinanceService;
import com.study.system.utils.RequestUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/finance")
public class FinanceController {

    @Resource
    private FinanceService financeService;

    /**
     * 获取社团财务信息
     *
     * @param clubIdInfo 财务Id
     * @return 财务信息列表
     */
    @PostMapping("/getFinanceInfo")
    public ResultData<List<Finance>> getFinanceInfo(@RequestBody Map<String, Integer> clubIdInfo) {
        return ResultData.success(financeService.getFinanceInfo(clubIdInfo.get("id")));
    }

    @PostMapping("/addFinanceInfo")
    public ResultData<Boolean> addFinanceInfo(HttpServletRequest request, @RequestBody Finance finance) {
        Integer userId = RequestUtil.getUserId(request);
        return ResultData.success(financeService.addFinanceInfo(userId, finance));
    }

    @PostMapping("/deleteFinanceInfo")
    public ResultData<Boolean> deleteFinanceInfo(@RequestBody Finance finance) {
        return ResultData.success(financeService.deleteFinanceInfo(finance.getId()));
    }

    @PostMapping("/updateFinanceInfo")
    public ResultData<Boolean> updateFinanceInfo(@RequestBody Finance finance) {
        return ResultData.success(financeService.updateFinanceInfo(finance));
    }

    @PostMapping("/searchFinanceInfoByTime")
    public ResultData<List<Finance>> searchFinanceInfoByTime(@RequestBody Finance finance) {
        return ResultData.success(financeService.searchFinanceInfoByTime(finance));
    }
}
